package com.lemon.smartsafety.ui.fragment.hidden;

import android.os.Bundle;
import android.support.v4.app.Fragment;

import com.lemon.smartsafety.R;
import com.lemon.smartsafety.app.EventTag;
import com.lemon.smartsafety.app.RefreshType;
import com.lemon.smartsafety.entity.event.hidden.HiddenMainRefreshEvent;
import com.lemon.smartsafety.http.service.HiddenServices;
import com.lemon.smartsafety.listener.RecyclerTClickListener;
import com.lemon.smartsafety.ui.adapter.hidden.list.HiddenListAdapter;
import com.lemon.smartsafetynew.ui.fragment.base.BasePullToRefreshFragment;
import com.lemon.smartsafety.utils.app.UIHelper;
import com.lemon.smartsafety.utils.common.LoggerHelper;
import com.lemon.safecloud.greendao.HiddenDangerInfo;

import org.greenrobot.eventbus.Subscribe;

import java.util.List;

import kale.adapter.LemonRcvAdapter;

/**
 * Created by Cooliean on 16/2/21.
 * 隐患一览
 */
public class HiddenListFragment extends BasePullToRefreshFragment<HiddenDangerInfo,List<HiddenDangerInfo>>
        implements RecyclerTClickListener<HiddenDangerInfo> {

    private LoggerHelper loggerHelper = new LoggerHelper(HiddenListFragment.class);



    public static Fragment newInstance() {
        HiddenListFragment fragment = new HiddenListFragment();
        return fragment;
    }

    @Override
    protected int getContentViewId() {
        return R.layout.fragment_refresh_no_title_no_divider;
    }

    @Override
    protected void initViews() {
        super.initViews();
    }

    @Override
    public boolean goRefreshOnCreate() {
        return true;
    }

    @Override
    public LemonRcvAdapter<HiddenDangerInfo> getLemonAdapter() {
        return new HiddenListAdapter(mDataList, this);
    }

    @Override
    public String getHttpTag() {
        return EventTag.TAG_HIDDEN_DANGER_LIST;
    }

    @Override
    public void onPullRefresh() {
        HiddenServices.init().getHiddenDangerInfoList(RefreshType.REFRESH, pageSize, currentPage, "0");
    }


    @Override
    public void onLoadMore() {
        HiddenServices.init().getHiddenDangerInfoList(RefreshType.LOAD_MORE, pageSize, currentPage, "0");
    }

    /**
     * 刷新事件
     * @param event
     */
    @Subscribe
    public void onEventMainThread(HiddenMainRefreshEvent event) {
        if (EventTag.TAG_HIDDEN_DANGER_MAIN_REFRESH.equals(event.getTag())) {
            mPullToRefreshRecyclerView.beginRefreshing();
        }
    }

    @Override
    public void onItemClick(HiddenDangerInfo data, int position) {
        Bundle bundle = new Bundle();
        bundle.putLong("info_id", data.getHiddenDangerId());
        UIHelper.showHiddenPropActivity(getActivity(), bundle);
    }
}
